package demo.standard;

public class ConcreteMediator extends AbstractMediator {

    private ConcreteColleagueA colleagueA;
    private ConcreteColleagueB colleagueB;

    @Override
    public void communicate(AbstractColleague sender, String info) {
        System.out.println("通过中介者进行同事间的通信：" + info);
        if (sender instanceof ConcreteColleagueA) {
            colleagueB.doSomethingForA();
        } else if (sender instanceof ConcreteColleagueB) {
            colleagueA.doSomethingForB();
        }
    }

    public void addColleague(AbstractColleague colleague) {
        if (colleague instanceof ConcreteColleagueA) {
            this.colleagueA = (ConcreteColleagueA) colleague;
        } else if (colleague instanceof ConcreteColleagueB) {
            this.colleagueB = (ConcreteColleagueB) colleague;
        }
    }
}
